using System;
using System.Runtime.InteropServices;


namespace SproxCalypsoAPI
{

  /************************************************************/
  public abstract class SproxCalypso
  {

    /**Constantes*********************/
    public const int ERR_WRONG_ADDR = -1000;
    public const int CALYPSO_ERR_WRONG_CMD = -1001;
    public const int CALYPSO_ERR_WRONG_LENGTH = -1002;
    public const int CALYPSO_ERR_WRONG_VALUE = -1003;
    public const int CALYPSO_ERR_OVERFLOW = -1004;

    /*********************************/


    /**ConfigureForCalypso************/
    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_ConfigureForCalypso")] public static extern short
ConfigureForCalypso();

    /*********************************/

    /**APGEN**************************/
    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_Calypso_APGEN")] public static extern short APGEN(byte pdc_addr,
                                                               byte
                                                               long_apgen,
                                                               byte with_atr,
                                                               byte occupancy,
                                                               byte[]repgen,
                                                               ref byte
                                                               repgen_len,
                                                               byte
                                                               []picc_uid4);

    /*********************************/

    /**ATTRIB*************************/
    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_Calypso_ATTRIB")] public static extern short ATTRIB(byte
                                                                 pcd_addr,
                                                                 byte
                                                                 picc_addr,
                                                                 byte
                                                                 []picc_uid4);

    /*********************************/

    /**COM_R**************************/
    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_Calypso_COM_R")] public static extern short COM_R(byte pcd_addr,
                                                               byte picc_addr,
                                                               byte
                                                               []iso_in_data,
                                                               byte
                                                               iso_in_data_len,
                                                               byte
                                                               []iso_out_data,
                                                               ref byte
                                                               iso_out_data_len);

    /*********************************/

    /**COM_RA*************************/
    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_Calypso_COM_RA")] public static extern short COM_RA(byte
                                                                 pcd_addr,
                                                                 byte
                                                                 picc_addr,
                                                                 byte
                                                                 []picc_uid4,
                                                                 byte
                                                                 []iso_in_data,
                                                                 byte
                                                                 iso_in_data_len,
                                                                 byte
                                                                 []iso_out_data,
                                                                 ref byte
                                                                 iso_out_data_len);

    /*********************************/

    /**DISC***************************/
    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_Calypso_DISC")] public static extern short DISC(byte pcd_addr,
                                                             byte picc_addr);

    /*********************************/

    /**WAIT***************************/
    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_Calypso_WAIT")] public static extern short WAIT(byte pcd_addr,
                                                             byte picc_addr);

    /*********************************/



    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_Calypso_Select")] public static extern short Select(byte slot);

    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_Calypso_Connect")] public static extern short Connect(byte[]atr,
                                                                   ref ushort
                                                                   atrlen);

    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_Calypso_Disconnect")] public static extern short Disconnect();

    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_Calypso_Exchange")] public static extern short
Exchange(byte[]iso_in_data, ushort iso_in_data_len, byte[]iso_out_data,
      ref ushort iso_out_data_len);

    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_Calypso_OpenSecureSession")] public static extern short
OpenSecureSession(byte card_key, byte[]sam_chal, byte[]card_chal,
               ref byte card_chal_size);

    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_Calypso_CloseSecureSession")] public static extern short
CloseSecureSession(byte[]sam_mac, byte[]card_mac);


    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_CalypsoSam_Select")] public static extern short Sam_Select(byte
                                                                        slot);

    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_CalypsoSam_Connect")] public static extern short
Sam_Connect(byte[]atr, ref ushort atrlen);

    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_CalypsoSam_Disconnect")] public static extern short
Sam_Disconnect();

    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_CalypsoSam_Exchange")] public static extern short
Sam_Exchange(byte[]iso_in_data, ushort iso_in_data_len, byte[]iso_out_data,
          ref ushort iso_out_data_len);

    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_CalypsoSam_SelectDiversifier_Atr")] public static extern short
Sam_SelectDiversifier_Atr(byte[]atr, ushort atrlen);

    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_CalypsoSam_GetChallenge")] public static extern short
Sam_GetChallenge(byte[]sam_chal);

    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_CalypsoSam_DigestInit")] public static extern short
Sam_DigestInit(byte sam_key, byte[]card_chal, byte card_chal_size);

    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_CalypsoSam_DigestUpdate")] public static extern short
Sam_DigestUpdate(byte[]iso_data, ushort iso_data_len);

    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_CalypsoSam_DigestClose")] public static extern short
Sam_DigestClose(byte[]sam_mac);

    [DllImport
     ("sprox_calypso.dll", CharSet = CharSet.Auto, CallingConvention =
      CallingConvention.Cdecl, EntryPoint =
      "SPROX_CalypsoSam_DigestAuthenticate")] public static extern short
Sam_DigestAuthenticate(byte[]card_mac);



  }                             // class SproxCalypso

  /************************************************************/
}
